package org.jeeasy.system.modules.premission.domain;

import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.dromara.autotable.annotation.mysql.MysqlTypeConstant;
import org.dromara.mpe.autotable.annotation.Column;
import org.dromara.mpe.autotable.annotation.Table;
import org.jeeasy.common.core.annotation.dict.Dict;
import org.jeeasy.common.core.base.BaseEntity;
import org.jeeasy.common.core.domain.vo.BaseTree;
import org.jeeasy.common.core.enums.BooleanEnum;
import org.jeeasy.system.enums.permission.LinkOpenTypeEnum;
import org.jeeasy.system.enums.permission.MenuTypeEnum;
import org.jeeasy.system.enums.permission.PermsTypeEnum;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

/**
 * 菜单权限表(sys_permission)实体类
 *
 * @author AlpsDDJ
 * @since 2020-11-21 13:52:05
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@Table(value = "sys_permission", comment = "菜单权限表")
@EqualsAndHashCode(callSuper = true)
public class SysPermission extends BaseEntity<SysPermission> implements BaseTree<SysPermission>, Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    public static final String TOP_ID = "0";

    /**
     * 父id
     */
    @Column(comment = "父id", length = 24)
    private String parentId;

    /**
     * 资源名称
     */
    @Column(comment = "资源名称", length = 32)
    private String name;

    /**
     * 路径
     */
    @Column(comment = "路径", length = 255)
    private String path;

    /**
     * 组件
     */
    @Column(comment = "组件", length = 32)
    private String component;

    /**
     * 组件名字
     */
    @Column(comment = "组件名字", length = 32)
    private String componentName;

    /**
     * 一级菜单跳转地址
     */
    @Column(comment = "一级菜单跳转地址", length = 255)
    private String redirect;

    /**
     * 菜单类型(0:一级菜单 1:子菜单 2:按钮权限)
     */
    @Column(comment = "菜单类型", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = MenuTypeEnum.class)
    private Integer menuType;

    /**
     * 菜单权限编码
     */
    @Column(comment = "菜单权限编码", length = 32)
    private String perms;

    /**
     * 权限策略     1显示2禁用
     */
    @Column(comment = "权限策略", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = PermsTypeEnum.class)
    private Integer permsType;

    /**
     * 菜单排序
     */
    @Column(comment = "菜单排序")
    private Double sortNo;

    /**
     * 聚合子路由: 1是0否
     */
    @Column(comment = "聚合子路由", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer alwaysShow;

    /**
     * 菜单图标
     */
    @Column(comment = "菜单图标")
    private String icon;

    /**
     * 是否路由菜单: 0:不是  1:是（默认值1）
     */
    @Column(comment = "是否路由菜单", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer route;

    /**
     * 是否叶子节点:    1:是   0:不是
     */
    @Column(comment = "是否叶子节点", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer leaf;

    /**
     * 是否缓存该页面:    1:是   0:不是
     */
    @Column(comment = "是否缓存该页面", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer keepAlive;

    /**
     * 是否隐藏路由: 0否,1是
     */
    @Column(comment = "是否隐藏路由", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer hidden;

    /**
     * 是否添加数据权限1是0否
     */
    @Column(comment = "是否添加数据权限", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer ruleFlag;

    /**
     * 按钮权限状态(0无效1有效)
     */
    @Column(comment = "启用标记", length = 1, type = MysqlTypeConstant.TINYINT)
    private Integer enableFlag;

    /**
     * 外链菜单打开方式 0/内部打开 1/外部打开
     */
    @Column(comment = "外链菜单打开方式", length = 1, type = MysqlTypeConstant.TINYINT)
    @TableField(updateStrategy = FieldStrategy.ALWAYS)
    @Dict(dictEnum = LinkOpenTypeEnum.class)
    private Integer internalOrExternal;

    @Column(comment = "描述", length = 255)
    private String description;

    @TableField(exist = false)
    private List<SysPermission> children;

}